package engine.content;

import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;




public class InMemoryContent implements IContent<InputStream, byte[]> {

	private byte[] b;
	private String contentType, contentBase, description;
	
	@Override
	public byte[] getContent() {
		return b;
	}

	@Override
	public ContentTypes getType() {
		return ContentTypes.MEMORY;
	}

	@Override
	public void setContent(InputStream content) {
		try {

			ByteArrayOutputStream str = new ByteArrayOutputStream();
			IOUtils.copy(content, str);
			this.b = str.toByteArray();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}

	}
	
	@Override
	public String getContentType() {
		return contentType;
		
	}

	@Override
	public void setContentType(String contentTypeStr) {
		this.contentType = contentTypeStr;
	}
	
	@Override
	public String getContentBase() {
		return contentBase;
		
	}

	@Override
	public void setContentBase(String contentBaseStr) {
		this.contentBase = contentBaseStr;
	}

	@Override
	public String getContentAsString() {
		throw new RuntimeException("not supported");
	}
	
	@Override
	public String getFileSuffix() {
		return contentType.substring(contentType.indexOf("/") +1);
	}
	@Override
	public String getDescription() {
		return this.description;
	}

	@Override
	public void setDescription(String setDescription) {
		this.description = setDescription;		
	}
}
